<template>
	<view class="checkIn">
		<u-navbar title="签到" :background="{ background: '#fe0000' }" back-icon-color="#fff" title-color="#fff" :border-bottom="false"></u-navbar>
		<view class="userInfo">
			<view class="info flex_conter">
				<image class="avatar" :src="user_info.user_headimg" mode="aspectFill"></image>
				<view class="data">
					<view class="uname">{{user_info.user_nickname}}</view>
					<view class="integral">拼团券：{{user_info.user_pintuan_sheng_num || 0}}</view>
				</view>
			</view>
			<!-- <view class="detail" @click="goDetail">
				<u-icon name="gengduo-2" custom-prefix="custom-icon" size="28" color="#ff9000"></u-icon>
				<text>明细</text>
			</view> -->
		</view>
		<view class="card">
			<view class="sevenDays flex_space_b">
				<view class="item" v-for="(item , index) in sign_set" :key="index">
					<view class="text">{{item.title}}</view>
					<view class="icon">
						<block v-if="continue_days>index">
							<image class="iconImage" v-if="item.is_reward == '10'"  src="../../static/checkedIn.png" mode="aspectFill"></image>
							<image class="iconImage" v-else src="../../static/rewardOn.png" mode="aspectFill"></image>
						</block>
						<block v-else>
							<image class="iconImage" v-if="item.is_reward == '10'"  src="../../static/notCheckedIn.png" mode="aspectFill"></image>
							<image class="iconImage" v-else src="../../static/reward.png" mode="aspectFill"></image>
						</block>
					</view>
				</view>
			
			</view>
			<view class="btnBox">
				<button v-if="!today_sign" type="default" class="btn notCheckedInBtn" @click="sign()">立即签到</button>
				<button v-else type="default" class="btn checkedIn">今日已签到</button>
			</view>
		</view>
		
		<view class="accumulated">
			<view class="title">已积累签到</view>
			<view class="accumulatedDays">
				<view class="item" v-for="(item,index) in days" :key="index">{{item}}</view>
				<text class="text">天</text>
			</view>
			<view class="remark">
				<view>{{user_info.tips_1 || ''}}</view>
				<!-- <view>连续签到更有积分或者现金礼包等你来拿</view> -->
			</view>
			<view class="checkedInList" v-if="false">
				<view class="item flex_space_b" v-for="(item, index) in [0, 1, 2]" :key="index">
					<view class="right">
						<view class="titleBox">签到奖励</view>
						<view class="time">2021-10-06</view>
					</view>
					<view class="left">+2.00</view>
				</view>
			</view>
			<view class="more" @click="goDetail" v-if="false">查看更多</view>
		</view>
		
		<u-mask :show="checkedInShow" @click="closeShow" :zoom="false">
			<view class="checkedInPopup">
				<image class="image" src="../../static/popupImage.png" mode="aspectFill"></image>
				<view class="title">签到奖励</view>
				<view class="reward">{{sign_tip}}</view>
				<button class="btn" type="default" @click="checkedInShow = false">好的</button>
			</view>
		</u-mask>
	</view>
</template>

<script>
	var util = require('../../common/util.js');
	export default {
		data() {
			return {
				checkedInShow: false,
				user_info:{},
				sign_set:[],
				today_sign:true,
				continue_days:0,
				days:[0,0,0,0],
				sign_tip:""
			}
		},
		onLoad() {
			if(util.is_wechat_xcx_auth()){
				this.loadData(true);
			}
		},
		methods: {
			loadData: function(is_loading){
				// 加载数据
				var that = this;
				util.requestPost("api.php/userSign/index", {}, function(res) {
					that.user_info = res.data.user_info;
					that.sign_set = res.data.sign_set;
					that.today_sign = res.data.today_sign;
					that.continue_days = res.data.continue_days;
					that.sign_tip = res.data.user_info.sign_tip;
					that.calcDays();
				},is_loading);
			},
			calcDays(){
				let total_sign_days = this.user_info['total_sign_days'] + "";
				let days = [];
				let j = 0;
				for(var i = 0;i<4;i++){
					if(total_sign_days.length > 3-i){
						days[i] = total_sign_days.substr(j,1);
						j++;
					}else{
						days[i] = 0;
					}
				}
				this.days = days;
			},
			sign(){
				// 加载数据
				var that = this;
				util.requestPost("api.php/userSign/sign", {}, function(res) {
					
					let today_sign = that.sign_set[that.continue_days];
					// if(today_sign.award_type == '10'){
					// 	that.sign_tip = "获得"+today_sign.award_amount+"积分";
					// }else{
					// 	that.sign_tip = "获得"+today_sign.award_amount+"元现金";
					// }
					
					that.checkedInShow = true;
					that.loadData();
				},true);
			},
			closeShow(){
				this.checkedInShow = false;
			},
			goDetail () {
				uni.navigateTo({
					url: '/pagesB/index/checkInDetail'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.checkIn {
	background-color: var(--bgColor);
	min-height: 100%;
	padding-bottom: 20rpx;
}
.userInfo {
	background: #fe0000;
	padding: 40rpx 28rpx 140rpx;
	position: relative;
	.info {
		.avatar {
			width: 100rpx;
			height: 100rpx;
			border: 6rpx solid #ecefcd;
			border-radius: 50%;
		}
		.data {
			margin-left: 20rpx;
			color: #FFFFFF;
			.uname {
				font-size: 32rpx;
				font-weight: 600;
			}
			.integral {
				background-color: var(--warningColor);
				padding: 4rpx 12rpx;
				border-radius: 8rpx;
				font-size: 24rpx;
				margin-top: 16rpx;
			}
		}
	}
	.detail {
		position: absolute;
		right: 0;
		top: 52rpx;
		color: var(--warningColor);
		background-color: #FFFFFF;
		padding: 20rpx 28rpx;
		border-radius: 40rpx 0 0 40rpx;
		text {
			margin-left: 8rpx;
		}
	}
}
.card {
	background-color: #FFFFFF;
	border-radius: 12rpx;
	padding: 70rpx 28rpx;
	margin: -80rpx 28rpx 14rpx;
	position: relative;
	z-index: 2;
	.sevenDays {
		.item {
			text-align: center;
			display: inline-block;
			.text {
				color: #666666;
				font-size: 24rpx;
				line-height: 32rpx;
			}
			.icon {
				width: 54rpx;
				height: 54rpx;
				margin: 0 auto;
				margin-top: 10rpx;
				.iconImage {
					width: 54rpx;
					height: 54rpx;
				}
			}
			&.reward {
				.text {
					color: #FFFFFF;
					background-color: var(--warningColor);
					border-radius: 32rpx;
				}
				.icon { 
					width: 74rpx;
					.iconImage {
						width: 74rpx;
						height: 54rpx;
					}
				}
				
			}
		}
		
	}
	.btnBox {
		margin-top: 72rpx;
		padding: 0 127rpx;
		.btn {
			border-radius: 50rpx;
		}
		.notCheckedInBtn {
			color: #FFFFFF;
			background-color: var(--warningColor);
		}
		.checkedIn {
			color: #FFFFFF;
			background-color: #999999;
		}
	}
}

.accumulated {
	background-color: #FFFFFF;
	border-radius: 12rpx;
	padding: 48rpx 28rpx;
	margin: 0 28rpx 14rpx;
	text-align: center;
	.title {
		font-size: 28rpx;
		color: #333333;
	}
	.accumulatedDays {
		margin-top: 40rpx;
		.item {
			display: inline-block;
			height: 116rpx;
			width: 80rpx;
			line-height: 116rpx;
			text-align: center;
			font-size: 62rpx;
			font-weight: 600;
			margin-right: 16rpx;
			color: #FFFFFF;
			background-color: var(--primaryColor);
			border-radius: 8rpx;
			vertical-align: bottom;
		}
		.text {
			vertical-align: bottom;
		}
	}
	.remark {
		color: #666666;
		margin-top: 52rpx;
		margin-bottom: 48rpx;
	}
	.checkedInList {
		border-top: 1px dashed #eee;
		.item {
			padding: 28rpx 0;
			border-bottom: 1px solid #EEEEEE;
			.right {
				.titleBox {
					font-size: 28rpx;
				}
				.time {
					font-size: 24rpx;
					color: #999999;
					margin-top: 8rpx;
				}
			}
			.left {
				color: var(--primaryColor);
			}
		}
	}
	.more {
		font-size: 28rpx;
		color: var(--assistColor);
		text-align: center;
		padding: 20rpx 0;
	}
}

.checkedInPopup {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	width: 520rpx;
	text-align: center;
	padding: 94rpx 80rpx 52rpx;
	border-radius: 12rpx;
	background-color: var(--primaryColor);
	.image {
		width: 134rpx;
		height: 120rpx;
		position: absolute;
		top: -60rpx;
		left: 50%;
		transform: translateX(-50%);
	}
	.title {
		font-size: 32rpx;
		color: #FFFFFF;
	}
	.reward {
		font-size: 28rpx;
		color: #ffcbc4;
		margin-top: 16rpx;
	}
	.btn {
		color: var(--primaryColor);
		background-color: #f8d168;
		border-radius: 52rpx;
		margin-top: 40rpx;
	}
}
</style>
